<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style>
    /*重新设置样式*/
    .form-control {
        width: 196px !important;
        height: 34px !important;
        padding: 10px !important;
    }
</style>
<body class="hold-transition skin-blue sidebar-mini" onload="checkBrowser()">
<!--标记面板-->
<div class="modal fade" id="modal-mark-panel">
    <div class="modal-dialog" style="width: 500px;">
        <div class="modal-content">
            <div class="modal-header" style="padding-bottom: 0px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑项目划库存标记信息</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 5px;padding-top: 0px;">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header" style="padding-bottom: 0px;">

                            </div>
                            <div class="box-body">
                                <form id="modalForm" class="form-horizontal">
                                    <div class="row">
                                        <input type="hidden" name="pimId">
                                        <input type="hidden" name="pimBeforeItyId">
                                        <input type="hidden" name="pimAppStatus">
                                        <div class="form-group" style="height: 60px">
                                            <label style="width: 90px;text-align: right">
                                                物料描述
                                            </label>
                                            <label>
                                                <input type="text" id="pimMatDesc" name="pimMatDesc"
                                                       class="form-control" readonly="readonly" style="width: 350px"/>
                                            </label>

                                        </div>
                                        <div class="form-group" style="height: 60px">
                                            <label style="width: 90px;text-align: right">SAP物料编码</label>
                                            <label>
                                                <input type="text" id="pimSapCode" name="pimSapCode"
                                                       class="form-control" readonly="readonly" style="width: 350px"/>
                                            </label>
                                        </div>
                                        <div class="form-group" style="height: 60px">
                                            <label style="width: 90px;text-align: right">项目编号</label>
                                            <label>
                                                <input type="text" id="pimBeforeProCode" name="pimBeforeProCode"
                                                       class="form-control"
                                                       readonly="readonly" style="width: 350px"/>
                                            </label>
                                        </div>
                                        <div class="form-group" style="height: 60px">
                                            <label style="width: 90px;text-align: right">项目名称</label>
                                            <label>
                                                <input type="text" id="pimBeforeProName" name="pimBeforeProName"
                                                       class="form-control"
                                                       readonly="readonly" style="width: 350px"/>
                                            </label>
                                        </div>
                                        <div class="form-group" style="height: 60px">
                                            <label style="width: 90px;text-align: right">可用数量</label>
                                            <label>
                                                <input type="text" id="pimBeforeAvaNum" name="pimBeforeAvaNum"
                                                       class="form-control"
                                                       readonly="readonly" style="width: 350px"/>
                                            </label>
                                        </div>
                                        <div class="form-group" style="height: 60px">
                                            <label style="width: 90px;text-align: right">
                                                标记数量
                                            </label>
                                            <label>
                                                <input type="text" id="pimNum" name="pimNum"
                                                       class="form-control"
                                                       placeholder="请输入标记数量" oninput="xyh.inputDecimalThree(this)"
                                                       style="width: 350px">
                                            </label>
                                        </div>
                                        <div class="form-group" style="height: 60px">
                                            <label style="width: 90px;text-align: right">
                                                划拨说明
                                            </label>
                                            <label>
                                                <input type="text" id="pimRemark" name="pimRemark"
                                                       class="form-control"
                                                       placeholder="请输入划拨说明"
                                                       style="width: 350px">
                                            </label>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="padding-top: 5px;">
                <button type="button" class="btn btn-info" id="btn-mark-commit">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>

</div>
<section class="content-header">
    <h1>项目划库存申请</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        项目编号
                                    </label>
                                    <label class="control-label">
                                        <input name="pimBeforeProCode" type="text" class="form-control text"

                                               placeholder="请输入项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        项目名称
                                    </label>
                                    <label class="control-label">
                                        <input name="pimBeforeProName" type="text" class="form-control text"
                                               maxlength="255"
                                               placeholder="请输入项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        物料描述
                                    </label>
                                    <label class="control-label">
                                        <input name="pimMatDesc" type="text" class="form-control text" maxlength="255"
                                               placeholder="请输入物料描述"/>
                                    </label>
                                </div>

                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        标记人
                                    </label>
                                    <label class="control-label">
                                        <input name="pimProposer" type="text" class="form-control text" maxlength="255"
                                               placeholder="请输入标记人信息"/>
                                    </label>
                                </div>
                                <div id="pimRemoveUserName" class="form-group"
                                     style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        申请删除者
                                    </label>
                                    <label class="control-label">
                                        <input name="pimRemoveUserName" type="text" class="form-control text"
                                               maxlength="255"
                                               placeholder="请输入申请删除者"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        生产状态
                                    </label>
                                    <label class="control-label">
                                        <select name="pimBeforeProStatus" class="form-control select"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: 100px!important;">
                                            <option value="" selected="selected">全部</option>
                                            <option value="-1">无状态</option>
                                            <option value="1">未开始</option>
                                            <option value="2">执行中</option>
                                            <option value="3">已完成</option>
                                            <option value="4">取消</option>
                                            <option value="5">暂缓</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        状态
                                    </label>
                                    <label class="control-label">
                                        <select name="pimAppStatus" class="form-control select"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: 100px!important;">
                                            <option value="">全部</option>
                                            <option value="1" selected>未提交</option>
                                            <option value="2">已驳回</option>
                                            <option value="3">已提交</option>
                                            <option value="4">已执行</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        删除状态
                                    </label>
                                    <label class="control-label">
                                        <select name="pimDataStatusStr" class="form-control"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: 60px!important;">
                                            <!--<option value="-1">全部</option>-->
                                            <option value="">全部</option>
                                            <option value="0" selected="selected">未删除</option>
                                            <option value="1">已删除</option>
                                        </select>
                                    </label>
                                </div>
                                <div id="removeDate" class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        删除日期范围
                                    </label>
                                    <label class="control-label">
                                        <input name="beginRemoveDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>-
                                        <input name="endRemoveDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        仓库
                                    </label>
                                    <label class="control-label">
                                        <select name="ityWhiId" class="form-control select"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;">

                                        </select>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        标记时间
                                    </label>

                                    <input name="beginDate" type="text"
                                           class="form-control datepicker" style="width: 100px!important;"
                                           readonly="readonly"> -
                                    <input name="endDate" type="text"
                                           class="form-control datepicker" style="width: 100px!important;"
                                           readonly="readonly">
                                </div>
                                <div id="submitDate" class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        提交日期范围
                                    </label>
                                    <label class="control-label">
                                        <input name="beginSubmitDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>-
                                        <input name="endSubmitDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <button type="button" class="btn btn-success" id="btn-search">搜索
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="row" id="toolbar">
                    <button shiro:hasPermission="purinv:purprowar:edit" type="button" class="btn btn-success"
                            onclick="submitApply('')">
                        批量提交
                    </button>
                    <a shiro:hasPermission="purinv:purprowar:edit" href="/purchase/proInv/create" class="btn btn-info"
                       id="btn-add-flag">新增标记</a>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" class="table table-bordered " width="100%">
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;
    var applyStatusText = ["删除", "未提交", "已驳回", "已提交", "已执行"];
    var applyStatusColor = ["", " bg-gray", " bg-red", " bg-green", " bg-green"];
    let columns = new Array();

    function checkBrowserFun() {
        let is360 = false;
        let isIE = false;
        let isFirefox = false;
        let isChrome = false;
        let isEdge = false;
        let broName = 'Runing';
        let str = '';
        let strStart = 0;
        let strStop = 0;
        let arr = new Array();
        let temp = '';
        let userAgent = window.navigator.userAgent; //包含以下属性中所有或一部分的字符串：appCodeName,appName,appVersion,language,platform
        /*alert(userAgent);*/
        //FireFox
        if (userAgent.indexOf('Firefox') != -1) {
            isFireFox = true;
            /*broName = 'FireFox浏览器';*/
            strStart = userAgent.indexOf('Firefox');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号')

        }
        //Edge
        if (userAgent.indexOf('Edge') != -1) {
            isEdge = true;
            /*broName = 'Edge浏览器';*/
            strStart = userAgent.indexOf('Edge');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号');
        }
        //IE浏览器
        if (userAgent.indexOf('NET') != -1 && userAgent.indexOf("rv") != -1) {
            isIE = true;
            /*broName = 'IE浏览器'; */
            strStart = userAgent.indexOf('rv');
            strStop = userAgent.indexOf(')');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('rv', 'IE').replace(':', '版本号');
        }
        //360极速模式可以区分360安全浏览器和360极速浏览器
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") < 0 && userAgent.indexOf("Firefox") < 0) {
            if (navigator.javaEnabled()) {
                is360 = true;
                broName = '360安全浏览器-极速模式';
            } else {
                is360 = true;
                broName = '360极速浏览器-极速模式';
            }
        }
        //360兼容
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") != -1 && userAgent.indexOf("MSIE") != -1 && userAgent.indexOf("rv") < 0) {
            is360 = true;
            broName = '360兼容模式';
        }
        //Chrome浏览器
        if (userAgent.indexOf('WOW') < 0 && userAgent.indexOf('Chrome') > 0 && userAgent.indexOf("Edg") < 0) {
            isChrome = true;
            /*broName = 'Chrome浏览器';*/
            strStart = userAgent.indexOf('Chrome');
            strStop = userAgent.indexOf(' Safari');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('/', '版本号');
        }
        return isChrome;
    }

    /**
     * 检测浏览器
     * */
    function checkBrowser(){
        if(!checkBrowserFun()){
            js.modal.warning("尊敬的客户，您使用浏览器不是谷歌浏览器，请使用谷歌浏览器访问本系统！");
            location.href=ctx+"overview/index";
        }
    }
    /**
     * 初始化页面中搜索框中元素的显隐
     **/
    function initQueryFormControl() {
        $("#pimRemoveUserName").hide();
        $("#removeDate").hide();
        columns = [
            {
                title: '<input style="width: 16px;height: 16px" title="全选" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                width: '30',
                field: 'pimId',
                formatter: function (value, row, index) {
                    var disabled = 'disabled="disabled"';
                    if (row.pimAppStatus == 1 || row.pimAppStatus == 2) {
                        disabled = "";
                    }
                    return '<input  style="width: 16px;height: 16px" ' + disabled + ' id="cb_change' + row.pimId + '" name="cb_change" data="' + row.pimId + '"  type="checkbox" />';
                }
            },
            {
                title: '序号', field: 'pimId', width: '50',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {title: '物料描述', field: 'pimMatDesc', width: '150'},
            {title: 'SAP物料编码', field: 'pimSapCode', width: '150'},
            {title: '标记数量', field: 'pimNum'},
            {title: '单位', field: 'pimNumUnit', width: '50'},
            {
                title: '单价', field: 'pimPrice', formatter: function (value, row, index) {
                    if(hasP('purinv:amount:view')){
                        return value;
                    }else {
                        return "***";
                    }
                }
            },
            {
                title: '项目编号', field: 'pimBeforeProCode', formatter: function (value, row, index) {
                    if (value == undefined || value == null) {
                        value = "--";
                    }
                    return value;
                }
            },
            {
                title: '项目名称', field: 'pimBeforeProName', width: '150', formatter: function (value, row, index) {
                    if (value == undefined || value == null) {
                        value = "--";
                    }
                    return value;
                }
            },
            {title: '生产状态', field: 'pimBeforeProStatus', width: '150'},
            {
                title: '仓库类型', field: 'pimItyType', width: '150', formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    if (value == 'p') {
                        return "外购件库";
                    }
                    if (value == 'm') {
                        return "原料库";
                    }
                    if (value == 'h') {
                        return "成品库";
                    }
                    return value;
                }
            },
            {
                title: '仓库', field: 'ityWhiName'
            },
            {
                title: '划拨说明', field: 'pimRemark'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '标记人', field: 'pimProposer'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '标记时间', field: 'pimDate', width: '100'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '提交时间', field: 'pimSubmitDate', width: '100'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '状态', field: 'pimAppStatus'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    var html = '<label class="badge ' + applyStatusColor[value] + '">' + applyStatusText[value] + '</label>';
                    return html;
                }
            }, {
                title: '驳回原因', field: 'pimRejectReaso'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '操作', field: 'ipmId', width: '140',
                formatter: function (value, row, index) {
                    var htmlText = "";
                    if (row.pimDataStatus == null && (row.pimAppStatus == 1 || row.pimAppStatus == 2)) {
                        if (hasP("purinv:purprowar:edit")) {
                            htmlText += '<button class="btn btn-warning btn-xs" onclick="showEditPanel(' + row.pimId + ')">修改</button>';
                            htmlText += '<button class="btn btn-success btn-xs" onclick="submitApply(' + row.pimId + ')">提交</button>';
                        }
                        if (hasP("purinv:purprowar:del")) {
                            htmlText += '<button onclick="removeApply(' + row.pimId + ')" class="btn btn-xs btn-danger">删除</button>';
                        }

                    }
                    return htmlText;
                }
            }
        ];
    }

    /**
     * 初始化数据
     * */
    function initData() {
        $('#bootstrap-table').bootstrapTable('destroy');
        //加载列表数据
        table = js.table.init({
            id: 'bootstrap-table',
            url: ctx + "purchase/proInv/apply/list",
            showColumns: true,
            showExport: false,
            pageSize: 300,
            // striped: false,
            uniqueId: "pimId",
            // onLoadSuccess: function () {
            //     $('#bootstrap-table thead th').each(function () {
            //         $(this).width(Math.floor($(this).width()));
            //     });
            //     $('#bootstrap-table tbody tr:first td').each(function () {
            //         $(this).width(Math.floor($(this).width()));
            //     });
            // },
            columns: columns
        });
    }

    /**
     *@FunctionName: showEditPanel
     *@Description: 显示编辑模板
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 14:11
     *@Phone: 18241927380
     *@Param:
     *@Return:
     *@Version:
     */
    function showEditPanel(pimId) {
        $.post(ctx + 'purchase/proInv/apply/getPProjectInventoryMark', {
            pimId: pimId
        }, function (result) {
            if (result.type == web_status.SUCCESS) {
                $("#modalForm").fillData(result.data);
                js.table.refresh(table);
                js.modal.open("modal-mark-panel");
            } else if (result.type == web_status.FAIL) {
                js.modal.fail(result.msg);
            }
        }, 'json');
        js.modal.open();
    }

    /**
     *@FunctionName: submitAppy
     *@Description: 提交
     *@Author: 徐一贺
     *@CreateDate: 2020/4/21 12:35
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function submitAppy(ipmId) {
        if (ipmId == '') {
            $('input[name="cb_change"]').each(function () {
                if (!$(this).prop("disabled")) {
                    if ($(this).prop("checked")) {
                        ipmId += $(this).attr("data") + ",";
                    }
                }
            })
            ipmId = ipmId.substring(0, ipmId.length - 1);
        }
        if (ipmId == '') {
            js.modal.warning("请选择要提交的库存划项目申请！");
            return;
        }
        js.modal.confirm("您确认要提交此标记吗？", function () {
            $.post(ctx + 'purchase/invPro/submitAppy', {
                ipmIds: ipmId
            }, function (result) {
                if (result.type == "SUCCESS") {
                    js.table.refresh(table);
                }
            }, 'json');
        });
    }


    /**
     *@FunctionName: search
     *@Description: 查询
     *@Author: 徐一贺
     *@CreateDate: 2020/4/10 16:10
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function search() {
        js.table.search(table);
    }

    /**
     *@FunctionName: selectAll
     *@Description: 全选
     *@Author: 徐一贺
     *@CreateDate: 2020/4/8 15:20
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function selectAll(obj) {
        $('input[name="cb_change"]').each(function () {
            if (!$(this).prop("disabled")) {
                if ($(obj).prop("checked")) {
                    $(this).prop("checked", true);
                }
                if ($(obj).prop("checked") == false) {
                    $(this).prop("checked", false);
                }
            }
        })

    }

    /**
     *@FunctionName: findWarehouseList
     *@Description: 获取仓库列表
     *@DesignIdea: 因为此页面是外购件页面，所以获取外购件仓库列表。
     *@Author: 徐一贺
     *@CreateDate: 2020/5/9 16:10
     *@Phone: 18241927380
     *@Param: []
     *@Version: v 1.0.0
     */
    function findWarehouseList() {
        js.ajax({
            url: ctx + 'common/warehouseInfo/list',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {},
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {

                    $("#queryForm [name='ityWhiId']").empty();
                    $("#queryForm [name='ityWhiId']").append('<option selected="selected" style="vertical-align: middle;text-align: center" value="">全部</option>');
                    for (var i = 0; i < result.data.rows.length; i++) {
                        $("#queryForm [name='ityWhiId']").append('<option style="vertical-align: middle;text-align: center" value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                    }
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     *@FunctionName: removeApply
     *@Description: 删除项目划库存申请
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 13:14
     *@Phone: 18241927380
     *@Param: [pimId] 主键
     *@Version: 1.0.0
     */
    function removeApply(pimId) {
        js.modal.confirm("尊敬的用户，您确认要删除此项目划库存申请吗？", function () {
            $.post(ctx + 'purchase/proInv/apply/remove', {
                pimIds: pimId
            }, function (result) {
                if (result.type == 'SUCCESS') {
                    js.table.refresh(table);
                    js.modal.success(result.msg);
                } else {
                    js.modal.fail(result.msg);
                }
            }, 'json');
        });
    }

    /**
     * 有权看钱没权看星
     * */
    function displayMoney(value) {
        if (hasP('purinv:amount:view')) {
            return value;
        } else {
            return '***';
        }
    }

    /**
     * 提交或批量提交
     * */
    function submitApply(pimId) {
        js.modal.confirm("尊敬的用户，您确认要提交选中的项目划库存申请吗？", function () {
            if (pimId == '') {
                $('input[name="cb_change"]').each(function () {
                    if (!$(this).prop("disabled")) {
                        if ($(this).prop("checked")) {
                            pimId += $(this).attr("data") + ",";
                        }
                    }
                })
                pimId = pimId.substring(0, pimId.length - 1);
            }
            if (pimId == '') {
                js.modal.alert("请选择要删除的项目划库存申请！");
                return;
            }
            $.post(ctx + 'purchase/proInv/apply/submit', {
                pimIds: pimId
            }, function (result) {
                if (result.type == 'SUCCESS') {
                    js.table.refresh(table);
                    js.modal.success(result.msg);
                } else {
                    js.modal.fail(result.msg);
                }
            }, 'json');
        });
    }

    $(function () {
        $("title").html($("title").html() + " —— 外购件项目划库存申请");
        findWarehouseList();
        initQueryFormControl();
        //加载列表数据
        initData();
        /**
         * 当选择删除状态时
         */
        $("#queryForm [name='pimDataStatusStr']").change(function () {
            if ($(this).val() === '1' || $(this).val() === '') {
                $("#pimRemoveUserName").show();
                $("#removeDate").show();
                $("#toolbar").hide();

                $('#bootstrap-table').bootstrapTable('destroy');
                //加载列表数据
                table = js.table.init({
                    id: 'bootstrap-table',
                    url: ctx + "purchase/proInv/apply/list",
                    showColumns: true,
                    showExport: false,
                    pageSize: 300,
                    // striped: false,
                    uniqueId: "pimId",
                    // onLoadSuccess: function () {
                    //     $('#bootstrap-table thead th').each(function () {
                    //         $(this).width(Math.floor($(this).width()));
                    //     });
                    //     $('#bootstrap-table tbody tr:first td').each(function () {
                    //         $(this).width(Math.floor($(this).width()));
                    //     });
                    // },
                    columns: [
                        {
                            title: '<input style="width: 16px;height: 16px" title="全选" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                            width: '30',
                            field: 'pimId',
                            formatter: function (value, row, index) {
                                var disabled = 'disabled="disabled"';
                                if (row.pimAppStatus == 1 || row.pimAppStatus == 2) {
                                    disabled = "";
                                }
                                return '<input  style="width: 16px;height: 16px" ' + disabled + ' id="cb_change' + row.pimId + '" name="cb_change" data="' + row.pimId + '"  type="checkbox" />';
                            }
                        },
                        {
                            title: '序号', field: 'pimId', width: '50',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {title: '物料描述', field: 'pimMatDesc', width: '150'},
                        {title: 'SAP物料编码', field: 'pimSapCode', width: '150'},
                        {title: '标记数量', field: 'pimNum'},
                        {title: '单位', field: 'pimNumUnit', width: '50'},
                        {
                            title: '项目编号', field: 'pimBeforeProCode', formatter: function (value, row, index) {
                                if (value == undefined || value == null) {
                                    value = "--";
                                }
                                return value;
                            }
                        },
                        {
                            title: '项目名称',
                            field: 'pimBeforeProName',
                            width: '150',
                            formatter: function (value, row, index) {
                                if (value == undefined || value == null) {
                                    value = "--";
                                }
                                return value;
                            }
                        },
                        {title: '生产状态', field: 'pimBeforeProStatus', width: '150'},
                        {
                            title: '仓库类型', field: 'pimItyType', width: '150', formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                if (value == 'p') {
                                    return "外购件库";
                                }
                                if (value == 'm') {
                                    return "原料库";
                                }
                                if (value == 'h') {
                                    return "成品库";
                                }
                                return value;
                            }
                        },
                        {
                            title: '仓库', field: 'ityWhiName'
                        },
                        {
                            title: '划拨说明', field: 'pimRemark'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '标记人', field: 'pimProposer'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '标记时间', field: 'pimDate', width: '100'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '提交时间', field: 'pimSubmitDate', width: '100'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '状态', field: 'pimAppStatus'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                var html = '<label class="badge ' + applyStatusColor[value] + '">' + applyStatusText[value] + '</label>';
                                return html;
                            }
                        }, {
                            title: '驳回原因', field: 'pimRejectReaso'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '删除状态', field: 'pimDataStatus'
                            , formatter: function (value, row, index) {
                                if (value === '1') {
                                    return "删除";
                                } else {
                                    return "未删除";
                                }
                            }
                        },
                        {
                            title: '删除操作者', field: 'pimRemoveUserName'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '删除时间', field: 'pimRemoveDate'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '操作', field: 'ipmId', width: '140',
                            formatter: function (value, row, index) {
                                var htmlText = "";

                                if (row.pimDataStatus == null && (row.pimAppStatus == 1 || row.pimAppStatus == 2)) {
                                    if (hasP("purinv:purprowar:edit")) {
                                        htmlText += '<button class="btn btn-warning btn-xs" onclick="showEditPanel(' + row.pimId + ')">修改</button>';
                                        htmlText += '<button class="btn btn-success btn-xs" onclick="submitApply(' + row.pimId + ')">提交</button>';
                                    }
                                    if (hasP("purinv:purprowar:del")) {
                                        htmlText += '<button onclick="removeApply(' + row.pimId + ')" class="btn btn-xs btn-danger">删除</button>';
                                    }

                                }
                                return htmlText;
                            }
                        }
                    ]
                });
                js.table.search(table);

            } else {
                $("#pimRemoveUserName").hide();
                $("#removeDate").hide();
                $("#toolbar").show();
                $('#bootstrap-table').bootstrapTable('destroy');
                //加载列表数据
                table = js.table.init({
                    id: 'bootstrap-table',
                    url: ctx + "purchase/proInv/apply/list",
                    showColumns: true,
                    showExport: false,
                    pageSize: 300,
                    // striped: false,
                    uniqueId: "pimId",
                    // onLoadSuccess: function () {
                    //     $('#bootstrap-table thead th').each(function () {
                    //         $(this).width(Math.floor($(this).width()));
                    //     });
                    //     $('#bootstrap-table tbody tr:first td').each(function () {
                    //         $(this).width(Math.floor($(this).width()));
                    //     });
                    // },
                    columns: [
                        {
                            title: '<input style="width: 16px;height: 16px" title="全选" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                            width: '30',
                            field: 'pimId',
                            formatter: function (value, row, index) {
                                var disabled = 'disabled="disabled"';
                                if (row.pimAppStatus == 1 || row.pimAppStatus == 2) {
                                    disabled = "";
                                }
                                return '<input  style="width: 16px;height: 16px" ' + disabled + ' id="cb_change' + row.pimId + '" name="cb_change" data="' + row.pimId + '"  type="checkbox" />';
                            }
                        },
                        {
                            title: '序号', field: 'pimId', width: '50',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {title: '物料描述', field: 'pimMatDesc', width: '150'},
                        {title: 'SAP物料编码', field: 'pimSapCode', width: '150'},
                        {title: '标记数量', field: 'pimNum'},
                        {title: '单位', field: 'pimNumUnit', width: '50'},
                        {title: '单价', field: 'pimPrice', formatter: function (value, row, index) {
                                if(hasP('purinv:amount:view')){
                                    return value;
                                }else {
                                    return "***";
                                }
                            }},
                        {
                            title: '项目编号', field: 'pimBeforeProCode', formatter: function (value, row, index) {
                                if (value == undefined || value == null) {
                                    value = "--";
                                }
                                return value;
                            }
                        },
                        {
                            title: '项目名称',
                            field: 'pimBeforeProName',
                            width: '150',
                            formatter: function (value, row, index) {
                                if (value == undefined || value == null) {
                                    value = "--";
                                }
                                return value;
                            }
                        },
                        {title: '生产状态', field: 'pimBeforeProStatus', width: '150'},
                        {
                            title: '仓库类型', field: 'pimItyType', width: '150', formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                if (value == 'p') {
                                    return "外购件库";
                                }
                                if (value == 'm') {
                                    return "原料库";
                                }
                                if (value == 'h') {
                                    return "成品库";
                                }
                                return value;
                            }
                        },
                        {
                            title: '仓库', field: 'ityWhiName'
                        },
                        {
                            title: '划拨说明', field: 'pimRemark'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '标记人', field: 'pimProposer'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '标记时间', field: 'pimDate', width: '100'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '提交时间', field: 'pimSubmitDate', width: '100'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '状态', field: 'pimAppStatus'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                var html = '<label class="badge ' + applyStatusColor[value] + '">' + applyStatusText[value] + '</label>';
                                return html;
                            }
                        }, {
                            title: '驳回原因', field: 'pimRejectReaso'
                            , formatter: function (value, row, index) {
                                if (value == undefined) {
                                    return "";
                                }
                                return value;
                            }
                        },
                        {
                            title: '操作', field: 'ipmId', width: '140',
                            formatter: function (value, row, index) {
                                var htmlText = "";

                                if (row.pimDataStatus == null && (row.pimAppStatus == 1 || row.pimAppStatus == 2)) {
                                    if (hasP("purinv:purprowar:edit")) {
                                        htmlText += '<button class="btn btn-warning btn-xs" onclick="showEditPanel(' + row.pimId + ')">修改</button>';
                                        htmlText += '<button class="btn btn-success btn-xs" onclick="submitApply(' + row.pimId + ')">提交</button>';
                                    }
                                    if (hasP("purinv:purprowar:del")) {
                                        htmlText += '<button onclick="removeApply(' + row.pimId + ')" class="btn btn-xs btn-danger">删除</button>';
                                    }

                                }
                                return htmlText;
                            }
                        }
                    ]
                });
                js.table.search(table);
            }

        });
        /**
         * 表格搜索
         */
        $("#btn-search").on('click', function () {
            js.table.search(table);
        });

        // 验证初始化
        js.validate.init("modalForm", {
            fields: {
                pimNum: {
                    validators: {
                        notEmpty: {message: '请输入标记数量'},
                    }
                },
                pimRemark: {validators: {notEmpty: {message: '请输入划拨说明'}}},
            }
        });

        /**
         * 保存修改
         * */
        $("#btn-mark-commit").on('click', function () {
            js.submit({
                url: ctx + "purchase/proInv/apply/saveMark",
                data:
                    new FormData($("#modalForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-mark-panel");
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            });
        });
    });
</script>
</body>
</html>
